<?php

namespace apiend\modules\attach\models;

use Yii;

/**
 * AlbumSearch represents the model behind the search form about [[\app\models\FanasocMemberApply]].
 * 
 * @author emhome <emhome@163.com>
 * @since 1.0
 */
class AlbumPictureSearch extends \common\models\shop\ShopAttachment {

    /**
     * @var string 关键字
     */
    public $keyword;

    /**
     * @var string 关键字
     */
    public $album_id;

    /**
     * @inheritdoc
     */
    public function rules() {
        return [
            [['album_id', 'keyword', 'store_id'], 'safe'],
        ];
    }

    /**
     * Searching member apply
     * @param  array $params
     * @return \yii\data\ActiveDataProvider
     */
    public function buildQuery() {
        $query = static::find()->alias('t')->active();
        $query->andWhere([
            't.store_id' => intval($this->store_id),
        ]);
        if ($this->album_id) {
            $query->andWhere([
                't.group_id' => $this->album_id,
            ]);
        }
        if ($this->keyword) {
            $condition = [
                'or',
                ['like', 't.title', $this->keyword],
                ['like', 't.path', $this->keyword],
            ];
            $query->andWhere($condition);
        }
        $query->orderBy([
            't.created_at' => SORT_DESC,
            't.group_id' => SORT_ASC,
        ]);
        $query->debug();
        return $query;
    }

    /**
     * {@inheritdoc}
     */
//    public function fields2() {
//        return [
//            'id',
//            'title',
//            'src',
//            'size',
//            'store_id',
//            'store',
//        ];
//    }
}
